package tlias.utils;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtils {
    public static String generateJwt(Map<String, Object> dataMap) {
        return Jwts.builder().signWith(SignatureAlgorithm.HS256, "c3NyczIwMjA=")
                .addClaims(dataMap)
                .setExpiration(new Date(System.currentTimeMillis()+3600*1000*24))
                .compact();
    }
    public static Integer getIdByJwt(String jwt) {
        Map<String, Object> claims = Jwts.parser()
                .setSigningKey("c3NyczIwMjA=")
                .parseClaimsJws(jwt)
                .getBody();
        return (Integer) claims.get("id");
    }
    public static void verifyJwt(String jwt) throws Exception{
        Jwts.parser().setSigningKey("c3NyczIwMjA=").parseClaimsJws(jwt);
    }
}
